把 Magento 想成「圖書館」:
關鍵一句:你改了資料(貼紙)不代表索引卡會立刻更新。
沒有 Reindex,前台常常就「沒變」或「不一致」。
因為 Magento 把商品、分類、價格、庫存…等資訊用 EAV 拆得很細,超彈性但查詢慢。
Reindex 會把這些分散資料「算好、整理好」,放進更好查詢的表,前台就能飛快讀到。
執行 bin/magento indexer:info
會看到一串,常見且影響大的有:
catalog_product_price
:單價、特價、階梯/群組價、規則價cataloginventory_stock
:庫存與可售狀態(in stock / out of stock)catalog_category_product
:商品與分類的對應catalogsearch_fulltext
:搜尋索引(ES / OpenSearch / MySQL 視版本設定)catalog_product_attribute
、catalog_product_flat
(若啟用)、catalogrule_rule
/catalogrule_product
(目錄價規則)這些就是「哪個前台功能會快、會準」的關鍵來源。
每個 indexer 都能切換模式:
切換指令:
# 全部設即時
bin/magento indexer:set-mode realtime
# 全部設排程
bin/magento indexer:set-mode schedule
# 看目前狀態
bin/magento indexer:status
bin/magento indexer:show-mode
catalog_product_entity_*_cl
這類 *_cl 表)。indexer_update_all_views
等)會把 changelog 的變動套用到目標索引表。所以「排程不起來」= 變動永遠卡在 changelog,前台就一直舊資料。
bin/magento indexer:status
是否 invalid
或卡 processing
。bin/magento indexer:reset
→ bin/magento indexer:reindex
(或等 cron 跑)。realtime
。schedule
,讓變動進 changelog,由 cron 批次吃。catalogsearch_fulltext
狀態、搜尋引擎服務(ES/OpenSearch)是否正常。bin/magento indexer:reindex catalogsearch_fulltext
,並確認搜尋服務健康度。# 全部重建
bin/magento indexer:reindex
# 指定某幾個
bin/magento indexer:reindex catalog_product_price cataloginventory_stock
# 重設狀態(把 processing/invalid 變可重建)
bin/magento indexer:reset
# 顯示模式 / 狀態
bin/magento indexer:show-mode
bin/magento indexer:status
Cache(如 FPC、block、config):把「算好的結果」存起來,下次直接拿。
Index:把「資料怎麼算」的中間結果整理好,讓前台查得快。
症狀判斷:
很多時候兩個都要處理:先 reindex,再清 cache。
變更前
schedule
。crontab -l
、bin/magento cron:run
手動驗證一次)。批量更新中
realtime
)。變更後
bin/magento indexer:reindex
(可選)或等待 cron 完成。回復日常
realtime
;schedule
。狀態一直是 processing
indexer:reset
再 reindex
。cron 沒跑
bin/magento cron:install
/ cron:remove
crond
、systemctl status crond
、容器排程策略。排程有在跑但一直沒更新
cron_schedule
是否塞滿失敗;var/log/system.log
、var/log/exception.log
是否有索引錯誤。搜尋索引成功但前台仍不準
indexer:status
、必要時 indexer:reindex
schedule
,確保 cron 正常catalogsearch_fulltext
+ 檢查搜尋服務indexer:reset
→ 再 reindexReindex 不是把資料「清掉重來」,而是把零碎資料整理成好查的結果表。
只要記住三件事:
realtime
、什麼時候用 schedule
;把這三件事做好,前台「怪怪的」的機率就會大幅下降。